package com.zhangdi.dwperms.commons.security;

import com.zhangdi.dwtools.consts.ConstValue;
import com.zhangdi.dwtools.security.Digests;
import org.apache.shiro.crypto.hash.SimpleHash;

public class Security {
    private int HASH_INTERATIONS = 1024;
    private int SALT_LENGTH = 24;
    private byte[] saltBytes = null;

    public String encrypt(String password) {
        if (null == saltBytes) {
            saltBytes = Digests.generateSalt(SALT_LENGTH);
        }
        return new SimpleHash(ConstValue.ALGORITHM_SHA_1, password, saltBytes, HASH_INTERATIONS).toHex();
    }

    public String getSalt() {
        return Encoder.encode(saltBytes);
    }
}
